library UnitType requires Table

    struct UnitType
        //单位ID
        integer m_unitId

        //作为目标类型
        string m_asTargetType
        //护甲类型
        string m_armorType
        //武器类型
        string m_weaponType
        //攻击类型
        string m_attackType

        //攻击范围
        real m_attackRange
        //模型路径
        string m_model
        //图标路径
        string m_icon
        //模型尺寸
        real m_modelScale
        //碰撞体积
        real m_collision
        //死亡时间
        real m_timeDeath
        //英雄主属性
        string m_primary

        private static Table cache

        private method reset takes nothing returns nothing
            set m_unitId = 0
            set m_asTargetType = "ground"
            set m_armorType = ""
            set m_weaponType = ""
            set m_attackType = ""
            set m_attackRange = 0.00
            set m_model = "Objects\\RandomObject\\RandomObject.mdl"
            set m_icon = "ReplaceableTextures\\CommandButtons\\BTNSelectHeroOn.blp"
            set m_modelScale = 1.00
            set m_collision = 16.00
            set m_timeDeath = 0.00
            set m_primary = "STR"
        endmethod

        static method get takes integer unitId returns UnitType
            return UnitType(cache[unitId])
        endmethod

        static method create takes integer unitId returns UnitType
            local UnitType this = UnitType.get(unitId)
            if this > 0 then
                return this
            endif
            set this = UnitType.allocate()
            call this.reset()

            set this.m_unitId = unitId
            set cache[unitId] = this
            return this
        endmethod

        method destroy takes nothing returns nothing
            call cache.remove(m_unitId)
            
            call this.reset()
            call this.deallocate()
        endmethod

        private static method onInit takes nothing returns nothing
            set cache = Table.create()
        endmethod
    endstruct

endlibrary